package com.walterweimod.auxiliary_attributes.util;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Random;

import static com.walterweimod.auxiliary_attributes.util.ModUtils.*;
import static com.walterweimod.auxiliary_attributes.Auxiliary_attributes.*;

public class ModRandomUtils {
    private void ModAttributes(){}

    public static float critical_hit_algorithm(float critical_hit_chance, float critical_hit_damage, float base_damage){
        Random random = new Random();
        float critical_hit_chance_percent = Math.min(critical_hit_chance / 100.0F, 1.0F);
        float random_data = random.nextFloat(1.0F);

        if (random_data <= critical_hit_chance_percent){
            getLogger().info("玩家触发暴击");

            base_damage += base_damage * critical_hit_damage / 100.0F;

            getLogger().info("玩家此次造成的暴击伤害为：" + base_damage);
        }

        return base_damage;
    }

    public static float afterDefense(float base_damage, float attacker_health, float defender_max_health, Collection<Float> defender_defense_values){
        if (Objects.nonNull(defender_defense_values) && !defender_defense_values.isEmpty()){
            getLogger().info("攻击者生命值为：" + attacker_health);
            getLogger().info("防御者最大生命值为：" + defender_max_health);
            getLogger().info("防御者防御力为：" + defender_defense_values);

            base_damage *= attacker_health / (attacker_health + defender_max_health / 20.0f * getProduct(defender_defense_values));

            getLogger().info("防御者最终受到的伤害为：" + base_damage);
        }

        return base_damage;
    }
}
